#! /usr/bin/python
# -*- coding: cp1250 -*-
#sys.path.append(r'C:\AFT\.pylib')

import string, sys
import pepe.p_txt.bigtxt as bt

def main(inp_file, out_file, inp_delimiter, out_delimiter):
    '''
    Purpose:    Strips blank spaces around delimiters of csv files.
    Syntax:     csv_strip <inp_file> <out_file> <inp_delimiter> <out_delimiter>
    Example:    csv_strip test.csv test_.csv \"|\" \"|\"   
    '''
    of = open(out_file, 'w')
    lino = 0
    for line in bt.lines(inp_file):
        lino += 1
        cols = string.split(line, inp_delimiter)
        bare_cols = [string.strip(c) for c in cols]
        of.write(string.join(bare_cols, out_delimiter)+'\n')
    of.close()

if __name__ == "__main__":
    if len(sys.argv) != 5:
        print main.__doc__
    else:
        main(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4])

